package controller

import (
	"admin/app/http/response"
	"admin/app/model"
	"admin/constant"
	"admin/tools"
	"net/http"

	"github.com/gin-gonic/gin"
)

type UserController struct {
}

func UserRegister(userGrp *gin.RouterGroup) {
	userController := &UserController{}
	userGrp.Use().POST("/findUser", userController.findUser)

	userGrp.Use().POST("/get", userController.getUser)

}

func (c UserController) getUser(ctx *gin.Context) {

	user, _ := ctx.Get("user")
	u := user.(model.User)

	response.Success(ctx, constant.SelectSuccessCode, constant.SelectSuccessMsg, gin.H{"token": u})
}

func (c UserController) findUser(ctx *gin.Context) {
	user, _ := ctx.Get("user")
	response.Success(ctx, constant.SelectSuccessCode, constant.SelectSuccessMsg, gin.H{"userName": user})
}

func Test(c *gin.Context) {
	res := tools.Config.Host
	c.JSON(http.StatusOK, gin.H{
		"message": res,
	})
}
